package com.wxdc.nmgyt.nmgytwydc.common;

import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.utils.CoordinateConverter;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * Created by Administrator on 2018/5/23.
 * 坐标转换
 */

public class CoordinateConvert {
    private static volatile CoordinateConvert instance;

    private CoordinateConvert() {

    }

    public static CoordinateConvert getInstance() {
        if (instance == null) {
            synchronized (CoordinateConvert.class) {
                if (instance == null) {
                    instance = new CoordinateConvert();
                }
            }
        }
        return instance;
    }

    /*
    将GPS设备采集的原始GPS坐标转换成百度坐标
    * */
    public LatLng latLngConVert(LatLng sourceLatLng) {
        CoordinateConverter converter = new CoordinateConverter();
        converter.from(CoordinateConverter.CoordType.GPS);
        // sourceLatLng待转换坐标
        converter.coord(sourceLatLng);
        LatLng desLatLng = converter.convert();
        return desLatLng;
    }

    /*
    * 将经纬度是度、分、秒格式转换成十进制表示法:
    *  如：106°14' 15" = 106.2375°
    * */
    public double jwdConvert(double d, double f, double m) {
        double result = 0.0;
        result = (m / 60 + f) / 60 + d;
        return Double.valueOf(String.format("%.10f", result));
    }

    /// <summary>
    /// 十进制转化为度分秒
    /// </summary>
    /// <param name="dValue"></param>十进制值
    /// <param name="iDegress"></param>获取的度
    /// <param name="iMinute"></param>获取的分
    /// <param name="dSecond"></param>获取的秒
    public String[] DecimalToDegree(double dValue) {
        int iDegress = (int) dValue;//获取度
        int iMinute = (int) ((dValue - iDegress) * 60);//获取分
        double dSecond = ((dValue - iDegress) * 60 - iMinute) * 60;//获取秒
        String strs = iDegress + "," + iMinute + "," + dSecond;

        return strs.split(",");
    }
}
